package org.example.factoryMethod.lazyLoad;

import org.example.factoryMethod.factoryMethodPl.ConcreteProduct1;
import org.example.factoryMethod.factoryMethodPl.ConcreteProduct2;
import org.example.factoryMethod.factoryMethodPl.Product;

import java.util.HashMap;
import java.util.Map;

public class ProductFactory {

    private static final Map<String, Product> prMap=new HashMap<>();

    public static synchronized Product createProduct(String type){
        Product product;

        if (prMap.containsKey(type)){
            product=prMap.get(type);
        }else {
            if (type.equals("Product1")){
                product=new ConcreteProduct1();
            }else {
                product=new ConcreteProduct2();
            }

            prMap.put(type,product);
        }

        return product;
    }
}
